package com.sright.bcard.common.service.share.dto.page;

import com.sright.bcard.common.service.share.dto.LoginUser;
import lombok.Data;

import javax.validation.constraints.NotNull;

/**
 * offset 分页请求参数dto类
 */
@Data
public class PageParamRequest extends LoginUser {
    private static final long serialVersionUID = -1797591528099092582L;


    public static PageParamRequest pageRequest(Integer pageIndex, Integer pageSize) {
        PageParamRequest request = new PageParamRequest();
        request.setOffset(pageIndex > 0 ? (pageIndex - 1) * pageSize : 0);
        request.setLimit(pageSize);
        return request;
    }

    public Integer getPageIndex() {
        if (limit != null && offset != null) {
            return  offset / limit + 1;
        }
        return 0;
    }

    public Integer getPageSize() {
        return limit;
    }


    /**
     * 偏移量(从多少跳开始查，跳过多少条)
     */
    @NotNull
    protected Integer offset;

    /**
     * 获取的数量
     */
    @NotNull
    protected Integer limit;
}
